package com.lb.controller;

import com.lb.entity.TbCinema;
import com.lb.service.TbCinemaService;
import com.lb.vo.SaLaVo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbCinema)表控制层
 *
 * @author libo
 * @since 2024-09-10 10:14:20
 */
@RestController
@RequestMapping("tbCinema")
public class TbCinemaController {
    /**
     * 服务对象
     */
    @Resource
    private TbCinemaService tbCinemaService;

    /**
     * 分页查询
     *
     * @param tbCinema    筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<TbCinema>> queryByPage(TbCinema tbCinema, PageRequest pageRequest) {
        return ResponseEntity.ok(this.tbCinemaService.queryByPage(tbCinema, pageRequest));
    }
    @GetMapping("/getList")
    public ResponseEntity<List<TbCinema>> queryAll() {
        return ResponseEntity.ok(this.tbCinemaService.queryAll());
    }
    @GetMapping("/getCinemaListDisCount")
    public ResponseEntity<List<TbCinema>>  getCinemaListDisCount(@RequestParam("movieId") String movieId){
        return ResponseEntity.ok(this.tbCinemaService.queryDisCount(movieId));
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<TbCinema> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.tbCinemaService.queryById(id));
    }
    @GetMapping("/getSaLa")
    public ResponseEntity<List<SaLaVo>> querySaLa(@RequestParam("movieId") Integer movieId, @RequestParam("cinemaId") Integer cinemaId) {
        return ResponseEntity.ok(this.tbCinemaService.querySaLaByMovieId(movieId,cinemaId));
    }
    /**
     * 新增数据
     *
     * @param tbCinema 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<TbCinema> add(TbCinema tbCinema) {
        return ResponseEntity.ok(this.tbCinemaService.insert(tbCinema));
    }

    /**
     * 编辑数据
     *
     * @param tbCinema 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<TbCinema> edit(TbCinema tbCinema) {
        return ResponseEntity.ok(this.tbCinemaService.update(tbCinema));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.tbCinemaService.deleteById(id));
    }

}

